using System;
using System.IO;
using System.Text;
using System.Collections.Generic;

public class Options
{
    private bool pHelp = false;
    private bool pCreate = false;
    private bool pExtract = false;
    private bool pList = false;
    private bool pTest = false;
    private string[] args;
    public string archive { get; set; }
    public List<string> files { get; set; }

    public Options(string[] args)
    {
        this.args = args;
        files = new List<string>();
    }

    public void parse()
    {
        if (args.Length >= 2 && args[0].Equals("list"))
        {
            pList = true;
            archive = args[1];
        }
        else if (args.Length >= 3 && args[0].Equals("create"))
        {
            pCreate = true;
            archive = args[1];

            for (int i = 2; i < args.Length; i++)
                files.Add(args[i]);
        }
        else if (args.Length >= 2 && args[0].Equals("extract"))
        {
            pExtract = true;
            archive = args[1];
        }
        else if (args.Length >= 2 && args[0].Equals("test"))
        {
            pTest = true;
            archive = args[1];
        }
        else
        {
            pHelp = true;
        }
    }

    public override string ToString()
    {
        StringBuilder deString = new StringBuilder();

        foreach (string arg in args)
            deString.Append(arg + "\n");


        if (pHelp)
            deString.Append("Help: enabled");
        else
            deString.Append("Help: disabled");

        return deString.ToString();
    }

    public bool help()
    {
        return pHelp;
    }

    public bool getExtract()
    {
        return pExtract;
    }

    public bool getCreate()
    {
        return pCreate;
    }

    public bool getTest()
    {
        return pTest;
    }

    public bool getList()
    {
        return pList;
    }
}

public class ParItCLI
{
    public ParItCLI()
    {
        
    }

    private void run(string[] args)
    {
        Options options = new Options(args);
        options.parse();
#if DEBUG
        Console.WriteLine(options);
#endif

        if (options.help())
        {
            help();
        }
        else if (options.getCreate())
        {
            ArchiveFactory factory = new ArchiveFactory();
            factory.createNew(options.archive, options.files);
        }
        else if (options.getList())
        {
            ArchiveFactory factory = new ArchiveFactory();
            Archive archive = factory.load(options.archive);
            Iterator it = archive.getIterator();

            while (it.hasNext())
                Console.WriteLine(it.next());
        }
        else if (options.getExtract())
        {
            ArchiveFactory factory = new ArchiveFactory();
            Archive archive = factory.load(options.archive);
            archive.extract(Directory.GetCurrentDirectory());
        }
        else if (options.getExtract())
        {
            ArchiveFactory factory = new ArchiveFactory();
            Archive archive = factory.load(options.archive);
            archive.test2();
        }
    }

    private void help()
    {
        Console.WriteLine("help");
    }

    public static void Main(string[] args)
    {
        ParItCLI parIt = new ParItCLI();
        parIt.run(args);
    }
}


